﻿using System.Collections.Generic;
using System.Threading.Tasks;
using Red.Controls.Diagrams;
using Red.Controls.Diagrams.ViewModels;
using Red.Controls.ViewModels;
using Red.Core.Containers;

namespace Red.Toolkit.NodeDeclaratorEditor
{
    public class DummyOutputsListDataItem : DataItem
    {
        #region Data

        private readonly NodeViewModel _node;

        #endregion Data

        #region C-tor

        public DummyOutputsListDataItem( NodeViewModel nodeViewModel )
            : base( null )
        {
            _node = nodeViewModel;
            Title = "Outputs";
            IsExpanded = true;
        }

        #endregion C-tor

        #region DataItem implementation

        public override string Type
        {
            get { return "Outputs"; }
        }

        public override string Value
        {
            get { return ""; }
            set { }
        }

        public override DataItemKind Kind
        {
            get { return DataItemKind.Container; }
        }

        protected override Task EnumerateChildrenAsync( IRangedCollection<DataItem> children )
        {
            if ( _node == null )
                return Task.FromResult( true );

            children.Clear();
            children.Add( new DataButtonItemBase( this, "Add Output", NodeControlCommands.AddDummyConnector ) );

            foreach ( var output in _node.OutputConnectors )
            {
                children.Add( new DummyOutputConnectorDataItem( this, output as DummyConnectorViewModel, _node.OutputConnectors.IndexOf( output ) ) );
            }

            return Task.CompletedTask;
        }

        #endregion DataItem implementation
    }
}
